ALTER DATABASE [RD_APMart] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [RD_APMart].[dbo].[sp_fulltext_database] @action = 'disable'
end
GO
ALTER DATABASE [RD_APMart] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [RD_APMart] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [RD_APMart] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [RD_APMart] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [RD_APMart] SET ARITHABORT OFF 
GO
ALTER DATABASE [RD_APMart] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [RD_APMart] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [RD_APMart] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [RD_APMart] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [RD_APMart] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [RD_APMart] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [RD_APMart] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [RD_APMart] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [RD_APMart] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [RD_APMart] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [RD_APMart] SET  ENABLE_BROKER 
GO
ALTER DATABASE [RD_APMart] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [RD_APMart] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [RD_APMart] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [RD_APMart] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [RD_APMart] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [RD_APMart] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [RD_APMart] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [RD_APMart] SET RECOVERY SIMPLE 
GO
ALTER DATABASE [RD_APMart] SET  MULTI_USER 
GO
ALTER DATABASE [RD_APMart] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [RD_APMart] SET DB_CHAINING OFF 
GO
EXEC sys.sp_db_vardecimal_storage_format N'RD_APMart', N'ON'
GO
ALTER AUTHORIZATION ON DATABASE::[RD_APMart] TO [FBCTORRANCE\aconsulting]
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_AP_MetricType]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE              PROCEDURE [dbo].[USP_AP_MetricType]
AS
--------------------------------------------------------------------------------------------------
--	Author:			c Copyright 2004 Andrews Consulting Group 
--	Procedure:		USP_AP_MetricType
--
--	Description:		Inserts table source identifiers into AP_Star_MetricType
--				Dimension Table.  This User Stored Procedure Is Run 
--				After Mart Creation.
--
--	Application:		After Install,  AP_Star_MetricType
--
--
--Modification History
--
--Date			Modified By		Description
--01.01.2001 		<developer name>	<comments>
-------------------------------------------------------------------------------------------------

TRUNCATE Table  RD_APMart.dbo.AP_Star_MetricType

INSERT INTO 
	RD_APMart.dbo.AP_Star_MetricType
VALUES
	(1,''1'',''Vouchers'', 0, ''1901/01/01'', 0, ''1901/01/01'', 0, ''1901/01/01'', ''1901/01/01'')
INSERT INTO 
	RD_APMart.dbo.AP_Star_MetricType
VALUES
	(2,''2'',''Payments'' , 0, ''1901/01/01'', 0, ''1901/01/01'', 0, ''1901/01/01'', ''1901/01/01'')
' 
END
GO
ALTER AUTHORIZATION ON [dbo].[USP_AP_MetricType] TO  SCHEMA OWNER 
GO
/****** Object:  StoredProcedure [dbo].[USP_AP_Star_FactsNightly]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_AP_Star_FactsNightly]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[USP_AP_Star_FactsNightly]
AS
BEGIN

UPDATE RD_APMart.dbo.AP_Star_Facts
SET HPaymentItemDocumentType = H.PaymentItemDocumentType,
 HPayItemNumber = H.PayItemNumber,
 HPayeeAddressNumber = H.PayeeAddressNumber,
 HCheckItemDateID = convert(bigint,convert (char(10),H.CheckItemDate,112))*100000+AP.COMPANYNUMBER,--Need to concatenate dateid and company number.
 HGLVoidDateID = convert(bigint,convert (char(10),H.GLVoidDate,112))*100000+AP.COMPANYNUMBER,
 HBatchNumber = H.BatchNumber,
 HBatchType = H.BatchType,
 HBatchDateId = convert(bigint,convert (char(10),H.BatchDate,112))*100000+AP.COMPANYNUMBER,
 HPaymentAmount = H.PaymentAmount,
 HCurrencyCode = H.CurrencyCode,
 HModeForeignOrDomestic = H.ModeForeignOrDomestic,
 HAccountMode01 = H.AccountMode01,
 HClearedValueDateID = convert(bigint,convert (char(10),H.ClearedValueDate,112))*100000+AP.COMPANYNUMBER,
 HPaymentInstrument = H.PaymentInstrument,
 HPaymentsPostStatus = H.PaymentsPostStatus,
 HCustomerBankAccountNumber = H.CustomerBankAccountNumber,
 HBankTapeReconcilliationRef = H.BankTapeReconcilliationRef,
 HTransactionOriginator = H.TransactionOriginator
FROM RD_APWork.DBO.JDEAPMATCHINGDOCUMENTHEADER H
INNER JOIN RD_APMart.dbo.AP_STAR_FACTS AP 
ON H.InternalPaymentId = AP.InternalPaymentId AND
 H.SourceID   = AP.SourceID
WHERE AP.TypeId = 2
END
' 
END
GO
ALTER AUTHORIZATION ON [dbo].[USP_AP_Star_FactsNightly] TO  SCHEMA OWNER 
GO
/****** Object:  StoredProcedure [dbo].[USP_AP_Star_Supplier_Refresh]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_AP_Star_Supplier_Refresh]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE               procedure [dbo].[USP_AP_Star_Supplier_Refresh]
AS
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--	Author:			c Copyright 2004 Andrews Consulting Group 
--	Procedure:		USP_AP_Star_Supplier_Refresh
--
--	Description:		User Stored Procedure To Populate the AP_Star_Supplier 
--				Dimension Address, Category Codes and Descriptions.  This User	
--				Stored Procedure Must Be Executed After Refresh Of AP_Star_Supplier
--				Table. 
--
--	Application:		 Refresh AP_Star_Supplier
--
--
--Modification History
--Date				Modified By			Description
--01.01.2001 		<developer name>	<comments>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------
----  Update Supplier Address Information  -----------------------------------
------------------------------------------------------------------------------
UPDATE 
	RD_APMart.dbo.AP_Star_Supplier
SET		
	SupplierName		= ABWSupl.MailingName
FROM 
	RD_APMart.dbo.AP_Star_Supplier SBM
INNER JOIN 
	RD_CommonWork.dbo.JDEABAddressBookWhosWho ABWSupl ON
		SBM.SupplierNumber 			= ABWSupl.AddressNumber AND
		SBM.SourceID 				= ABWSupl.SourceID 
WHERE	
	ABWSupl.WhosWhoLine = (Select Min(WhosWhoLine) from 
				RD_CommonWork.dbo.JDEABAddressBookWhosWho AWW1
				Where AWW1.AddressNumber = ABWSupl.AddressNumber and 
				      AWW1.SourceID = ABWSupl.SourceID)

UPDATE 
	RD_APMart.dbo.AP_Star_Supplier
SET		
	SupplierAddressline01 	= ABDSupl.AddressLine1,
	SupplierAddressline02 	= ABDSupl.AddressLine2,
	SupplierAddressline03 	= ABDSupl.AddressLine3,
	SupplierAddressline04 	= ABDSupl.AddressLine4,
	SupplierPostalCode	= ABDSupl.PostalCode,
	SupplierCity		= ABDSupl.City,
	SupplierCounty		= ABDSupl.County,
	SupplierStateCode	= ABDSupl.StateCode,
	SupplierState		= ABDSupl.State,
	SupplierCountry		= ABDSupl.Country,
	SupplierCountryCode 	= ABDSupl.CountryCode
FROM 
	RD_APMart.dbo.AP_Star_Supplier SBM
INNER JOIN	
	RD_CommonWork.dbo.JDEABAddressBookAddressByDate ABDSupl ON
		SBM.SupplierNumber 			= ABDSupl.AddressNumber  AND
		SBM.SourceID 				= ABDSupl.SourceID
WHERE
		ABDSupl.EffectiveFromDate 		= 1

------------------------------------------------------------------------------
----  Update Supplier Parent Address Information  ----------------------------
------------------------------------------------------------------------------

-- Update ParentID Field, value in OrgStructure if found (default = suppliernumber)
UPDATE
	RD_APMart.dbo.AP_Star_Supplier
SET
	ParentNumber	= SORG.ParentNumber 
FROM 
	RD_APMart.dbo.AP_Star_Supplier SBM
INNER JOIN  
	RD_CommonWork.dbo.JDEABAddressBookOrgStructure SORG  ON
		SBM.SupplierNumber 	= SORG.AddressNumber AND 
		SBM.SourceID 		= SORG.SourceID 
WHERE
		SORG.StructureType	= '' ''


-- Update Mailing Name Information
UPDATE RD_APMart.dbo.AP_Star_Supplier
SET			
	ParentName   			= ABWParent.MailingName
FROM
	RD_APMart.dbo.AP_Star_Supplier SBM
INNER JOIN
	RD_CommonWork.dbo.JDEABAddressBookWhosWho ABWParent ON
		SBM.ParentNumber 	= ABWParent.AddressNumber AND
		SBM.SourceID 		= ABWParent.SourceID
WHERE	
	ABWParent.WhosWhoLine = (Select Min(WhosWhoLine) from 
				RD_CommonWork.dbo.JDEABAddressBookWhosWho AWW1
				Where AWW1.AddressNumber = ABWParent.AddressNumber and 
				      AWW1.SourceID = ABWParent.SourceID)


-- Update Parent Address Information
UPDATE
	RD_APMart.dbo.AP_Star_Supplier
SET
	ParentAddressLine01		= ABDParent.AddressLine1,
	ParentAddressLine02		= ABDParent.AddressLine2,
	ParentAddressLine03		= ABDParent.AddressLine3,
	ParentAddressLine04		= ABDParent.AddressLine4,
	ParentPostalCode 		= ABDParent.PostalCode,
	ParentCity 			= ABDParent.City, 	ParentCounty 			= ABDParent.County,
	ParentStateCode			= ABDParent.StateCode,
	ParentState 			= ABDParent.State,
	ParentCountry 			= ABDParent.Country,
	ParentCountryCode 		= ABDParent.CountryCode
FROM
	RD_APMart.dbo.AP_Star_Supplier SBM
INNER JOIN
	RD_CommonWork.dbo.JDEABAddressBookAddressByDate ABDParent ON
		SBM.parentNumber 	= ABDParent.AddressNumber AND
		SBM.SourceID 		= ABDParent.SourceID 
WHERE
		ABDParent.EffectiveFromDate = 1

------------------------------------------------------------------------------
----  Update Supplier Category Information 			--------------
------------------------------------------------------------------------------
UPDATE
	RD_APMart.dbo.AP_Star_Supplier
SET
	SearchTypeCode		= ABM.SearchTypeCode,
	SearchType		= ABM.SearchType,
	Category01Code		= ABM.Category01Code,
	Category01		= ABM.Category01,
	Category02Code		= ABM.Category02Code,
	Category02		= ABM.Category02,
	Category03Code		= ABM.Category03Code,
	Category03		= ABM.Category03,
	Category04Code		= ABM.Category04Code,
	Category04		= ABM.Category04,
	Category05Code		= ABM.Category05Code,
	Category05		= ABM.Category05,
	Category06Code		= ABM.Category06Code,
	Category06		= ABM.Category06,
	Category07Code		= ABM.Category07Code,
	Category07		= ABM.Category07,
	Category08Code		= ABM.Category08Code,
	Category08		= ABM.Category08,
	Category09Code		= ABM.Category09Code,
	Category09		= ABM.Category09,
	Category10Code		= ABM.Category10Code,
	Category10		= ABM.Category10,
	Category11Code		= ABM.Category11Code,
	Category11		= ABM.Category11,
	Category12Code		= ABM.Category12Code,
	Category12		= ABM.Category12,
	Category13Code		= ABM.Category13Code,
	Category13		= ABM.Category13,
	Category14Code		= ABM.Category14Code,
	Category14		= ABM.Category14,
	Category15Code		= ABM.Category15Code,
	Category15		= ABM.Category15,
	Category16Code		= ABM.Category16Code,
	Category16		= ABM.Category16,
	Category17Code		= ABM.Category17Code,
	Category17		= ABM.Category17,
	Category18Code		= ABM.Category18Code,
	Category18		= ABM.Category18,
	Category19Code		= ABM.Category19Code,
	Category19		= ABM.Category19,
	Category20Code		= ABM.Category20Code,
	Category20		= ABM.Category20,
	Category21Code		= ABM.Category21Code,
	Category21		= ABM.Category21,
	Category22Code		= ABM.Category22Code,
	Category22		= ABM.Category22,
	Category23Code		= ABM.Category23Code,
	Category23		= ABM.Category23,
	Category24Code		= ABM.Category24Code,
	Category25		= ABM.Category25,
	Category26Code		= ABM.Category26Code,
	Category26		= ABM.Category26,
	Category27Code		= ABM.Category27Code,
	Category27		= ABM.Category27,
	Category28Code		= ABM.Category28Code,
	Category28		= ABM.Category28,
	Category29Code		= ABM.Category29Code,
	Category29		= ABM.Category29,
	Category30Code		= ABM.Category30Code,
	Category30		= ABM.Category30
FROM
	RD_APMart.dbo.AP_Star_Supplier SBM
INNER JOIN
	RD_CommonWork.dbo.JDEABAddressBookMaster ABM ON
		SBM.SupplierNumber 	= ABM.AddressNumber AND
		SBM.SourceID		= ABM.SourceID



------------------------------------------------------------------------------
----  Update Payment Terms Information  -----------------------------------
------------------------------------------------------------------------------
UPDATE 
	RD_APMart.dbo.AP_Star_Supplier
SET		
	PaymentTerms		= PT.Description
FROM 
	RD_APMart.dbo.AP_Star_Supplier SBM
INNER JOIN 
	RD_APWork.dbo.JDEGSPaymentTerms PT ON
		SBM.PaymentTermsAP 			= PT.PaymentTerms AND
		SBM.SourceID 				= PT.SourceID
' 
END
GO
ALTER AUTHORIZATION ON [dbo].[USP_AP_Star_Supplier_Refresh] TO  SCHEMA OWNER 
GO
/****** Object:  StoredProcedure [dbo].[USP_Load_Orphans_AP]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_Load_Orphans_AP]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--	Author:			c Copyright 2004 Andrews Consulting Group 
--	Procedure:		USP_LOAD_ORPHANS_AP
--
--	Description:	User Stored Procedure To Populate the table
--					storing orphans.
--						
--
--	Application:	Load Orphans table
--
--
--Modification History
--Date				Modified By			Description
--08.18.2006		Craig Scott			Created.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

CREATE  PROCEDURE [dbo].[USP_Load_Orphans_AP] @DateRun DATETIME
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	-- Clear the table of any previous records for this mart
	-- then load it again for a one time run.
	--DELETE FROM RD_COMMON.DBO.ORPHANS WHERE vchMart = ''APMART''

	INSERT RD_COMMON.DBO.ORPHANS
	SELECT DISTINCT ''APMART'', @DateRun, ''BusinessUnit'',T1.BusinessUnitCode, COUNT(T1.BusinessUnitCode)
	FROM RD_APMART.DBO.AP_Star_Facts T1
	LEFT JOIN RD_Common.dbo.Star_BusinessUnit T2 ON
	T2.BusinessUnitCode = T1.BusinessUnitCode
	AND T2.SOURCEID = T1.SOURCEID
	WHERE T2.BusinessUnitCode IS NULL
	GROUP BY T1.BusinessUnitCode
	
	INSERT RD_COMMON.DBO.ORPHANS
	SELECT DISTINCT ''APMART'',@DateRun, ''Company'',T1.CompanyNumber, COUNT(T1.CompanyNumber)
    FROM RD_APMART.DBO.AP_Star_Facts T1
    LEFT JOIN RD_Common.dbo.Star_Company T2 ON
 	T1.CompanyNumber = T2.CompanyNumber 
	AND T2.SOURCEID = T1.SOURCEID
	WHERE T2.CompanyNumber IS NULL 
	GROUP BY T1.CompanyNumber

	INSERT RD_COMMON.DBO.ORPHANS
	SELECT DISTINCT ''APMART'', @DateRun, ''Supplier'', T1.AddressNumber, COUNT(T1.AddressNumber)	
	FROM RD_APMART.DBO.AP_Star_Facts T1
	LEFT JOIN RD_APMART.DBO.AP_Star_Supplier T2 ON
	T2.SupplierNumber = T1.AddressNumber
	AND T2.SourceID = T1.SourceID
	WHERE T2.SupplierNumber IS NULL
	GROUP BY T1.AddressNumber
	
	INSERT RD_COMMON.DBO.ORPHANS
	SELECT DISTINCT ''APMART'', @DateRun, ''DocumentType'', T1.DocumentTypeCode, COUNT(T1.DocumentTypeCode)	
	FROM RD_APMART.DBO.AP_Star_Facts T1
	LEFT JOIN RD_APMART.DBO.AP_Star_Type T2 ON
	T2.DocumentTypeCode  = T1.DocumentTypeCode 
	AND T2.SourceID = T1.SourceID
	WHERE T2.DocumentTypeCode  IS NULL
	GROUP BY T1.DocumentTypeCode


	INSERT RD_COMMON.DBO.ORPHANS
	SELECT DISTINCT ''APMART'', @DateRun, ''InvoiceDateID'', T1.InvoiceDateID, COUNT(T1.InvoiceDateID)	
	FROM RD_APMART.DBO.AP_Star_Facts T1
	LEFT JOIN RD_APMART.DBO.AP_Star_Dates T2 ON
	T2.CompanyDateID  = T1.InvoiceDateID
	WHERE T2.CompanyDateID  IS NULL
	GROUP BY T1.InvoiceDateID

	INSERT RD_COMMON.DBO.ORPHANS
	SELECT DISTINCT ''APMART'', @DateRun, ''GLDateID'', T1.GLDateID, COUNT(T1.GLDateID)	
	FROM RD_APMART.DBO.AP_Star_Facts T1
	LEFT JOIN RD_APMART.DBO.AP_Star_Dates T2 ON
	T2.CompanyDateID  = T1.GLDateID
	WHERE T2.CompanyDateID  IS NULL
	GROUP BY T1.GLDateID

	
END
' 
END
GO
ALTER AUTHORIZATION ON [dbo].[USP_Load_Orphans_AP] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[AP_Star_Facts]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AP_Star_Facts](
	[BusinessUnitID] [char](20) NOT NULL,
	[CompanyNumberID] [bigint] NOT NULL,
	[SupplierNumberID] [bigint] NOT NULL,
	[TypeID] [char](10) NOT NULL,
	[PaymentTermsID] [char](20) NOT NULL,
	[TransactionTypeID] [int] NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[DocumentCompany] [char](5) NOT NULL,
	[DocumentNumber] [int] NOT NULL,
	[DocumentTypeCode] [char](2) NOT NULL,
	[PayItem] [char](3) NOT NULL,
	[PayItemExtensionNumber] [int] NOT NULL,
	[AdjustingDocumentType] [char](2) NOT NULL,
	[InternalPaymentID] [decimal](15, 0) NOT NULL,
	[FileLineIdentifier] [decimal](5, 0) NOT NULL,
	[AddressNumber] [int] NOT NULL,
	[InvoiceDateID] [bigint] NOT NULL,
	[DueDateID] [bigint] NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[CompanyNumber] [char](5) NOT NULL,
	[PayStatus] [char](1) NOT NULL,
	[GrossAmount] [decimal](20, 7) NOT NULL,
	[OpenAmount] [decimal](20, 7) NOT NULL,
	[ServiceDateTaxID] [bigint] NOT NULL,
	[DiscountDueDateID] [bigint] NOT NULL,
	[GLDateID] [bigint] NOT NULL,
	[BatchDateID] [bigint] NOT NULL,
	[DiscountAvailable] [decimal](20, 7) NOT NULL,
	[DiscountTaken] [decimal](20, 7) NOT NULL,
	[TaxableAmount] [decimal](20, 7) NOT NULL,
	[NonTaxableAmount] [decimal](20, 7) NOT NULL,
	[TaxAmount] [decimal](20, 7) NOT NULL,
	[CurrencyAmount] [decimal](20, 7) NOT NULL,
	[ForeignOpenAmount] [decimal](20, 7) NOT NULL,
	[ForeignDiscountAvailable] [decimal](20, 7) NOT NULL,
	[ForeignDiscountTaken] [decimal](20, 7) NOT NULL,
	[ForeignTaxableAmount] [decimal](20, 7) NOT NULL,
	[ForeignNonTaxableAmount] [decimal](20, 7) NOT NULL,
	[ForeignTaxAmount] [decimal](20, 7) NOT NULL,
	[GLOffset] [char](4) NOT NULL,
	[GLBankAccount] [char](8) NOT NULL,
	[GLPostedCode] [char](1) NOT NULL,
	[AccountMode01] [char](1) NOT NULL,
	[GLCreditAccountID] [char](8) NOT NULL,
	[ObjectAccount] [char](6) NOT NULL,
	[Subsidiary] [char](8) NOT NULL,
	[OriginalOrderDocumentCompany] [char](5) NOT NULL,
	[OriginalDocumentType] [char](2) NOT NULL,
	[OriginalDocumentNumber] [int] NOT NULL,
	[OriginalPayItem] [char](3) NOT NULL,
	[PaymentHandlingCode] [char](3) NOT NULL,
	[InvoiceNumber] [char](25) NOT NULL,
	[PurchaseOrderDocumentCompany] [char](5) NOT NULL,
	[PONumber] [char](8) NOT NULL,
	[PurchaseOrderDocumentType] [char](2) NOT NULL,
	[LineNumber] [decimal](20, 7) NOT NULL,
	[OrderSuffix] [char](3) NOT NULL,
	[OperationsSequenceNumber] [decimal](20, 7) NOT NULL,
	[Reference1] [char](25) NOT NULL,
	[AssetBusinessUnit] [char](12) NOT NULL,
	[Remark] [char](30) NOT NULL,
	[Units] [decimal](20, 7) NOT NULL,
	[UnitOfMeasure] [char](2) NOT NULL,
	[PaymentInstrument] [char](1) NOT NULL,
	[UserReservedDateID] [bigint] NOT NULL,
	[UserReservedAmount] [decimal](20, 7) NOT NULL,
	[UserReservedNumber] [int] NOT NULL,
	[AmountToDistribute] [decimal](20, 7) NOT NULL,
	[AmountCurrencyToDistribute] [decimal](20, 7) NOT NULL,
	[NonRecoverableTaxAmount] [decimal](20, 7) NOT NULL,
	[ForeignNonRecoverableTax] [decimal](20, 7) NOT NULL,
	[GenericAmount1] [decimal](20, 7) NOT NULL,
	[GenericAmount2] [decimal](20, 7) NOT NULL,
	[FutureWithholdTaxAmtDomestic] [decimal](20, 7) NOT NULL,
	[FutureWithholdTaxAmtForeign] [decimal](20, 7) NOT NULL,
	[PaymentItemDocumentType] [varchar](2) NOT NULL,
	[PaymentAmount] [decimal](22, 7) NOT NULL,
	[PaymentAmountForeign] [decimal](22, 7) NOT NULL,
	[ModeForeignOrDomestic] [char](1) NOT NULL,
	[CurrencyCode] [char](3) NOT NULL,
	[CurrencyConversionRateSpot] [decimal](20, 7) NOT NULL,
	[CashBasisAccountingPostCode] [char](1) NOT NULL,
	[GLPeriodNumber] [decimal](2, 0) NOT NULL,
	[FiscalYear] [int] NOT NULL,
	[ClosedStatement] [char](1) NOT NULL,
	[HistoricalExchangeRate] [decimal](15, 7) NOT NULL,
	[HPaymentItemDocumentType] [char](2) NOT NULL,
	[HPayItemNumber] [decimal](8, 0) NOT NULL,
	[HPayeeAddressNumber] [decimal](8, 0) NOT NULL,
	[HCheckItemDateID] [bigint] NOT NULL,
	[HGLVoidDateID] [bigint] NOT NULL,
	[HBatchNumber] [decimal](8, 0) NOT NULL,
	[HBatchType] [varchar](2) NOT NULL,
	[HBatchDateID] [bigint] NOT NULL,
	[HPaymentAmount] [decimal](22, 7) NOT NULL,
	[HCurrencyCode] [char](3) NOT NULL,
	[HModeForeignOrDomestic] [char](1) NOT NULL,
	[HAccountMode01] [char](1) NOT NULL,
	[HClearedValueDateID] [bigint] NOT NULL,
	[HPaymentInstrument] [char](1) NOT NULL,
	[HPaymentsPostStatus] [char](1) NOT NULL,
	[HCustomerBankAccountNumber] [varchar](20) NOT NULL,
	[HBankTapeReconcilliationRef] [char](8) NOT NULL,
	[HTransactionOriginator] [varchar](10) NOT NULL,
	[HInternalPaymentID] [decimal](15, 0) NOT NULL,
	[HGLBankAccount] [char](8) NOT NULL,
	[HUserID] [char](10) NOT NULL,
	[HProgramID] [char](10) NOT NULL,
	[HDateUpdatedID] [bigint] NOT NULL,
	[HLastTimeUpdated] [int] NOT NULL,
	[HWorkStationID] [char](10) NOT NULL,
	[HMulticurrencyIntercompanyPay] [char](2) NOT NULL,
	[HLocalizationReservedFlag] [char](2) NOT NULL,
	[HPurgeFlag] [char](2) NOT NULL,
	[HPositivePayFlag] [char](2) NOT NULL,
	[HGenericFlag8] [char](2) NOT NULL,
	[HGenericAmount3] [decimal](20, 7) NOT NULL,
	[HGenericAmount4] [decimal](20, 7) NOT NULL,
	[HGenericString6] [char](50) NOT NULL,
	[HGenericString7] [char](50) NOT NULL,
	[HNettingTransactionID] [int] NOT NULL,
	[HNettingDocumentNumber] [int] NOT NULL,
	[HContractID] [int] NOT NULL,
	[HContractCode] [char](12) NOT NULL,
	[HHarvestID] [int] NOT NULL,
	[HBlockCode] [char](10) NOT NULL,
	[HHarvestPeriod] [char](6) NOT NULL,
	[HHarvestSuffix] [char](10) NOT NULL,
	[PayeeAddressNumber] [int] NOT NULL,
	[ApproverNumber] [int] NOT NULL,
	[BatchNumber] [int] NOT NULL,
	[BatchType] [char](2) NOT NULL,
	[BalancedJE] [char](1) NOT NULL,
	[TaxRateArea] [char](10) NOT NULL,
	[TaxExplanationCode] [char](2) NOT NULL,
	[SubledgerType] [char](1) NOT NULL,
	[SubLedger] [char](8) NOT NULL,
	[BankTransitShortID] [char](8) NOT NULL,
	[PaymentTerms] [char](3) NOT NULL,
	[VoidFlag] [char](1) NOT NULL,
	[UnitNumber] [char](8) NOT NULL,
	[RecurFrequency] [char](2) NOT NULL,
	[NumberOfPayments] [int] NOT NULL,
	[StatementNumber] [char](13) NOT NULL,
	[TaxArea3Withholding] [char](10) NOT NULL,
	[TaxExplCode3Withholding] [char](2) NOT NULL,
	[MiscellaneousCode01] [char](1) NOT NULL,
	[MiscellaneousCode02] [char](1) NOT NULL,
	[CashRcptsInvRegCode] [char](1) NOT NULL,
	[Category07Code] [char](3) NOT NULL,
	[FlagFor1099] [char](1) NOT NULL,
	[DomesticEntryWMultiCurrDistr] [char](1) NOT NULL,
	[ItemNumber] [int] NOT NULL,
	[HistoricalDateID] [bigint] NOT NULL,
	[UserReservedCode] [char](3) NOT NULL,
	[UserReservedReference] [char](15) NOT NULL,
	[TransactionOriginator] [char](10) NOT NULL,
	[TransitNumberBank] [char](20) NOT NULL,
	[CategoryCodeAPLedger01] [char](3) NOT NULL,
	[CategoryCodeAPLedger02] [char](3) NOT NULL,
	[CategoryCodeAPLedger03] [char](3) NOT NULL,
	[CategoryCodeAPLedger04] [char](3) NOT NULL,
	[CategoryCodeAPLedger05] [char](3) NOT NULL,
	[CategoryCodeAPLedger06] [char](3) NOT NULL,
	[CategoryCodeAPLedger07] [char](3) NOT NULL,
	[CategoryCodeAPLedger08] [char](3) NOT NULL,
	[CategoryCodeAPLedger09] [char](3) NOT NULL,
	[CategoryCodeAPLedger10] [char](3) NOT NULL,
	[DeferredTaxStatusVAT] [char](1) NOT NULL,
	[PurchasingTaxableYN] [char](1) NOT NULL,
	[PurgeFlag] [char](1) NOT NULL,
	[GenericFlag5] [char](1) NOT NULL,
	[GenericFlag6] [char](1) NOT NULL,
	[GenericString4] [char](25) NOT NULL,
	[GenericString5] [char](25) NOT NULL,
	[SummarizedFlag] [char](1) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[DateUpdatedID] [bigint] NOT NULL,
	[LastTimeUpdated] [int] NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[CurrencyCodeBase] [char](6) NOT NULL,
	[LocalizationReservedFlag] [char](2) NOT NULL,
	[PositivePayFlag] [char](2) NOT NULL,
	[GenericFlag8] [char](2) NOT NULL,
	[GenericAmount3] [decimal](20, 7) NOT NULL,
	[GenericAmount4] [decimal](20, 7) NOT NULL,
	[GenericString6] [char](50) NOT NULL,
	[GenericString7] [char](50) NOT NULL,
	[DiscountReasonCode] [char](6) NOT NULL,
	[PayWhenPaid] [char](1) NOT NULL,
	[PayWhenPaidGroupNumber] [int] NOT NULL,
	[NettingTransactionID] [int] NOT NULL,
	[NettingDocumentNumber] [int] NOT NULL,
	[NettingLineID] [int] NOT NULL,
	[NettingStatusCode] [char](1) NOT NULL,
	[ContractID] [int] NOT NULL,
	[ContractCode] [char](12) NOT NULL,
	[HarvestID] [int] NOT NULL,
	[BlockCode] [char](10) NOT NULL,
	[HarvestPeriod] [char](6) NOT NULL,
	[HarvestSuffix] [char](10) NOT NULL,
	[DueDateRule] [char](5) NOT NULL,
	[SequenceNumber] [int] NOT NULL,
	[ReconciledCode] [char](1) NOT NULL,
	[Ref3AccountReconciliation] [char](8) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_AP_Star_Facts] PRIMARY KEY CLUSTERED 
(
	[DocumentCompany] ASC,
	[DocumentNumber] ASC,
	[DocumentTypeCode] ASC,
	[PayItem] ASC,
	[PayItemExtensionNumber] ASC,
	[AdjustingDocumentType] ASC,
	[InternalPaymentID] ASC,
	[FileLineIdentifier] ASC,
	[AddressNumber] ASC,
	[TransactionTypeID] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
ALTER AUTHORIZATION ON [dbo].[AP_Star_Facts] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[AP_Star_TransactionType]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_TransactionType]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AP_Star_TransactionType](
	[TransactionTypeID] [int] NOT NULL,
	[TransactionTypeCode] [int] NOT NULL,
	[TransactionType] [char](30) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_AP_Star_MetricType] PRIMARY KEY CLUSTERED 
(
	[TransactionTypeCode] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
ALTER AUTHORIZATION ON [dbo].[AP_Star_TransactionType] TO  SCHEMA OWNER 
GO
/****** Object:  View [dbo].[AP_Star_BusinessUnit]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_BusinessUnit]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[AP_Star_BusinessUnit]
AS
SELECT     *
FROM         RD_Common.dbo.Star_BusinessUnit

' 
GO
ALTER AUTHORIZATION ON [dbo].[AP_Star_BusinessUnit] TO  SCHEMA OWNER 
GO
/****** Object:  View [dbo].[AP_Star_BusinessUnitSecurity]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_BusinessUnitSecurity]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[AP_Star_BusinessUnitSecurity]
AS
SELECT     *
FROM         RD_CommonWork.dbo.JDEBOBusinessUnitSecurity
' 
GO
ALTER AUTHORIZATION ON [dbo].[AP_Star_BusinessUnitSecurity] TO  SCHEMA OWNER 
GO
/****** Object:  View [dbo].[AP_Star_Company]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Company]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[AP_Star_Company]
AS
SELECT     *
FROM         RD_Common.dbo.Star_Company

' 
GO
ALTER AUTHORIZATION ON [dbo].[AP_Star_Company] TO  SCHEMA OWNER 
GO
/****** Object:  View [dbo].[AP_Star_Dates]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Dates]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[AP_Star_Dates]
AS
SELECT     *
FROM         RD_Common.dbo.Star_Dates
' 
GO
ALTER AUTHORIZATION ON [dbo].[AP_Star_Dates] TO  SCHEMA OWNER 
GO
/****** Object:  View [dbo].[AP_Star_PaymentTerms]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_PaymentTerms]'))
EXEC dbo.sp_executesql @statement = N'
CREATE view [dbo].[AP_Star_PaymentTerms]
as 
select *
from RD_Common.dbo.Star_PaymentTerms

' 
GO
ALTER AUTHORIZATION ON [dbo].[AP_Star_PaymentTerms] TO  SCHEMA OWNER 
GO
/****** Object:  View [dbo].[AP_Star_Supplier]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Supplier]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[AP_Star_Supplier]
AS
SELECT     SupplierNumberID, SourceID, Source, SupplierNumber, SupplierName, SupplierAddressLine01, SupplierAddressLine02, SupplierAddressLine03, 
                      SupplierAddressLine04, SupplierPostalCode, SupplierCity, SupplierCounty, SupplierStateCode, SupplierState, SupplierCountry, SupplierCountryCode, 
                      ParentNumber, ParentName, ParentAddressLine01, ParentAddressLine02, ParentAddressLine03, ParentAddressLine04, ParentPostalCode, ParentCity, 
                      ParentCounty, ParentStateCode, ParentState, ParentCountry, ParentCountryCode, SupplierParentRebatelevel, SupplierRebateCode, 
                      CustomerTypeIdentifier, HoldOrdersCode, RouteCode, StopCode, ZoneNumber, CarrierCode, GLClass, PaymentInstrument, ApproverNumber, 
                      PaymentTermsAP, PaymentTerms, RelatedAddressNumber, SearchTypeCode, SearchType, Category01Code, Category01, Category02Code, 
                      Category02, Category03Code, Category03, Category04Code, Category04, Category05Code, Category05, Category06Code, Category06, Category07Code,
                       Category07, Category08Code, Category08, Category09Code, Category09, Category10Code, Category10, Category11Code, Category11, 
                      Category12Code, Category12, Category13Code, Category13, Category14Code, Category14, Category15Code, Category15, Category16Code, Category16,
                       Category17Code, Category17, Category18Code, Category18, Category19Code, Category19, Category20Code, Category20, Category21Code, 
                      Category21, Category22Code, Category22, Category23Code, Category23, Category24Code, Category24, Category25Code, Category25, Category26Code,
                       Category26, Category27Code, Category27, Category28Code, Category28, Category29Code, Category29, Category30Code, Category30, InsertIndicator, 
                      InsertDate, ChangeIndicator, ChangeDate, DeleteIndicator, DeleteDate, PurgeDate
FROM         RD_Common.dbo.Star_Supplier

' 
GO
ALTER AUTHORIZATION ON [dbo].[AP_Star_Supplier] TO  SCHEMA OWNER 
GO
/****** Object:  View [dbo].[AP_Star_Type]    Script Date: 5/30/13 12:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Type]'))
EXEC dbo.sp_executesql @statement = N'


CREATE  VIEW [dbo].[AP_Star_Type]
AS
SELECT     
	   Cast(substring(UserdefinedCodesValues,9,2) + Cast(SourceID as char(5)) as char(10)) as ''TypeID'',
	   SourceID, 
	   Cast(Source as char(20)) as ''Source'', 
	   Cast(Description02 as char(30)) as ''Level1'', 
	   '' '' as ''Level2'', 
	   Cast(substring(UserdefinedCodesValues,9,2) as varchar(2)) as ''DocumentTypeCode'', 
	   Cast(Description01 as char(30)) as ''DocumentType'',
	   InsertIndicator,
	   InsertDate,
                ChangeIndicator,
                ChangeDate,
 	   DeleteIndicator,
	   DeleteDate,
	   PurgeDate
FROM     RD_CommonWork.dbo.JDEGSUserDefinedCodes
WHERE InstallSystemCode= ''00''  AND UserDefinedCode = ''DT''



' 
GO
ALTER AUTHORIZATION ON [dbo].[AP_Star_Type] TO  SCHEMA OWNER 
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_Facts_BusinessUnitID]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_BusinessUnitID')
CREATE NONCLUSTERED INDEX [IX_Facts_BusinessUnitID] ON [dbo].[AP_Star_Facts]
(
	[BusinessUnitID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_CompanyID]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_CompanyID')
CREATE NONCLUSTERED INDEX [IX_Facts_CompanyID] ON [dbo].[AP_Star_Facts]
(
	[CompanyNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_CompanyNumberID]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_CompanyNumberID')
CREATE NONCLUSTERED INDEX [IX_Facts_CompanyNumberID] ON [dbo].[AP_Star_Facts]
(
	[CompanyNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_DiscountDueDate]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_DiscountDueDate')
CREATE NONCLUSTERED INDEX [IX_Facts_DiscountDueDate] ON [dbo].[AP_Star_Facts]
(
	[DiscountDueDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_Facts_DocumentType]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_DocumentType')
CREATE NONCLUSTERED INDEX [IX_Facts_DocumentType] ON [dbo].[AP_Star_Facts]
(
	[DocumentTypeCode] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_DueDate]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_DueDate')
CREATE NONCLUSTERED INDEX [IX_Facts_DueDate] ON [dbo].[AP_Star_Facts]
(
	[DueDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_GLDate]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_GLDate')
CREATE NONCLUSTERED INDEX [IX_Facts_GLDate] ON [dbo].[AP_Star_Facts]
(
	[GLDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_HBatchDate]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_HBatchDate')
CREATE NONCLUSTERED INDEX [IX_Facts_HBatchDate] ON [dbo].[AP_Star_Facts]
(
	[HBatchDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_HCheckItemDate]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_HCheckItemDate')
CREATE NONCLUSTERED INDEX [IX_Facts_HCheckItemDate] ON [dbo].[AP_Star_Facts]
(
	[HCheckItemDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_HClearedValueDate]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_HClearedValueDate')
CREATE NONCLUSTERED INDEX [IX_Facts_HClearedValueDate] ON [dbo].[AP_Star_Facts]
(
	[HClearedValueDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_HGLVoidDate]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_HGLVoidDate')
CREATE NONCLUSTERED INDEX [IX_Facts_HGLVoidDate] ON [dbo].[AP_Star_Facts]
(
	[HGLVoidDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_InternalPaymentID]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_InternalPaymentID')
CREATE NONCLUSTERED INDEX [IX_Facts_InternalPaymentID] ON [dbo].[AP_Star_Facts]
(
	[InternalPaymentID] ASC,
	[TransactionTypeID] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_InvoiceDate]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_InvoiceDate')
CREATE NONCLUSTERED INDEX [IX_Facts_InvoiceDate] ON [dbo].[AP_Star_Facts]
(
	[InvoiceDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_MetricType]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_MetricType')
CREATE NONCLUSTERED INDEX [IX_Facts_MetricType] ON [dbo].[AP_Star_Facts]
(
	[TransactionTypeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_Facts_PaymentTermsID]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_PaymentTermsID')
CREATE NONCLUSTERED INDEX [IX_Facts_PaymentTermsID] ON [dbo].[AP_Star_Facts]
(
	[PaymentTermsID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_ServiceDateTax]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_ServiceDateTax')
CREATE NONCLUSTERED INDEX [IX_Facts_ServiceDateTax] ON [dbo].[AP_Star_Facts]
(
	[ServiceDateTaxID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_SupplierNumberID]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_SupplierNumberID')
CREATE NONCLUSTERED INDEX [IX_Facts_SupplierNumberID] ON [dbo].[AP_Star_Facts]
(
	[SupplierNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_Facts_TypeID]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_TypeID')
CREATE NONCLUSTERED INDEX [IX_Facts_TypeID] ON [dbo].[AP_Star_Facts]
(
	[TypeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Facts_UserReservedDate]    Script Date: 5/30/13 12:54:05 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AP_Star_Facts]') AND name = N'IX_Facts_UserReservedDate')
CREATE NONCLUSTERED INDEX [IX_Facts_UserReservedDate] ON [dbo].[AP_Star_Facts]
(
	[UserReservedDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
USE [master]
GO
ALTER DATABASE [RD_APMart] SET  READ_WRITE 
GO
